<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>餐桌列表</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  {include file="public/css"/}
    <style>
        #urlqr img{margin:0 auto}
        .timeset .layui-input{ display:inline;height:30px}
    </style>
</head>
<body>
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-card layui-col-md12">
          <div class="layui-card-header">餐桌列表</div>
            <blockquote class="layui-elem-quote">客人用餐后，请使用手机端后台“餐桌管理”清台，后续客人可继续点餐</blockquote>

            <div class="layui-card-body" pad15>
            <div class="layui-col-md4" style="padding-bottom:10px">
                <a class="layui-btn layuiadmin-btn-list" href="javascript:void(0)" onclick="openmax('{:url('edit')}')">添加</a>
                <button class="layui-btn layui-btn-primary layuiadmin-btn-list" onclick="datadel(0)">删除</button>
                <button class="layui-btn layui-btn-primary layuiadmin-btn-list" onclick="createTable()">批量生成</button>
            </div>
                <div class="layui-form layui-col-md8 layui-form-search">
                    <div class="layui-inline layuiadmin-input-useradmin">
                        <label class="layui-form-label">餐桌名称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="name" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                   
                    <div class="layui-inline">
                        <button class="layui-btn layuiadmin-btn-replys" lay-submit="" lay-filter="LAY-app-forumreply-search">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                    </div>
                </div>
            <div class="layui-col-md12">
                <table id="tabledata" lay-filter="tabledata"></table>
            </div>
          </div>
        </div>
    </div>
  </div>
	{include file="public/js"/}
	<script>
  var table = layui.table;
	var datawhere = {};
  //数据表
  var tableIns = table.render({
    elem: '#tabledata'
    ,url: "{$Request.url}" //数据接口
    ,page: true //开启分页
    ,cols: [[ //表头
          {type:"checkbox"},
          {field: 'id', title: 'ID',  width:80},
          {field: 'name', title: '名称'},
          {field: 'pic', title: '图片', templet: '<div>{{# if(d.pic){ }}<img src="{{d.pic}}" style="height:60px"/>{{# } }}</div>'},
          {field: 'cid', title: '分类', width:80, templet: function (d) {
                  if (d.category !== null) return d.category.name;
                  return '';
              }
          },
          {field: 'seat', title: '座位数', width:80},
          {field: 'sort', title: '排序',width:80},
          //{field: 'createtime', title: '创建时间',templet:function(d){ return date('Y-m-d H:i',d.createtime)},width:150},
          {if getcustom('restaurant_table_after_pay_clean')}
          {field: 'auto_clean', title: '自动清台',templet:function(d){ if(d.auto_clean==1) return '<span style="color:#008000">开启</span>'; else if(d.auto_clean==0) return '<span style="color:red">关闭</span>';},width:80},
          {/if}
          {field: 'canbook', title: '预定',templet:function(d){ if(d.canbook==1) return '<span style="color:#008000">开启</span>'; else if(d.canbook==0) return '<span style="color:red">关闭</span>';},width:80},
          {if getcustom('restaurant_shop_pindan')}
          {field: 'pindan_status', title: '餐后付款',templet:function(d){ if(d.pindan_status==1) return '<span style="color:#008000">开启</span>'; else if(d.pindan_status==0) return '<span style="color:red">关闭</span>';},width:80},
          {/if}
          {field: 'status', title: '状态',templet:function(d){ if(d.status==1) return '<span style="color:#008000">预定</span>'; else if(d.status==-1) return '<span style="color:red">禁用</span>'; else if(d.status==0) return '<span style="color:green">空闲</span>'; else if(d.status==2) return '<span style="color:orange">入座</span>'; else if(d.status==3) return '<span style="color:orange">清台</span>';},width:80},
          {if getcustom('restaurant_shop_pinzhuo')}
            {field: 'pinzhuo_status', title: '拼桌模式',templet:function(d){ if(d.pinzhuo_status==1) return '<span style="color:#008000">开启</span>'; else if(d.pinzhuo_status==0) return '<span style="color:red">关闭</span>';},width:80},
          {/if}
          {field: 'operation', title: '操作',templet: function(d){
				var html = '';
				html += '<button class="table-btn" onclick="openmax(\'{:url('edit')}/id/'+d.id+'\')">编辑</button>';
                  html += '<button class="table-btn" onclick="showurl('+d.id+')">查看链接和二维码</button>';
				html += '<button class="table-btn" onclick="datadel('+d.id+')">删除</button>';
				if(d.deep==0 || d.deep==1){
					html += '<button class="table-btn" onclick="openmax(\'{:url('edit')}/pid/'+d.id+'\')">添加子分类</button>';
				}
				return html;
      },width:250}
    ]]
  });
	//排序
	table.on('sort(tabledata)', function(obj){
		datawhere.field = obj.field;
		datawhere.order = obj.type;
		tableIns.reload({
			initSort: obj,
			where: datawhere
		});
	});
	//检索
	layui.form.on('submit(LAY-app-forumreply-search)', function(obj){
		var field = obj.field
		var olddatawhere = datawhere
		datawhere = field
		datawhere.field = olddatawhere.field
		datawhere.order = olddatawhere.order
		tableIns.reload({
			where: datawhere,
			page: {curr: 1}
		});
	})
  function showurl(id){
      var pagepath = 'restaurant/shop/index?tableId='+id;
    pagepath = pagepath + '&bid=' + {$bid};
    viewLink(pagepath);
  }
	//删除
	function datadel(id){
		var ids = [];
		if(id==0){
			var checkStatus = table.checkStatus('tabledata')
			var checkData = checkStatus.data; //得到选中的数据
			if(checkData.length === 0){
				 return layer.msg('请选择数据');
			}
			var ids = [];
			for(var i=0;i<checkData.length;i++){
				ids.push(checkData[i]['id']);
			}
		}else{
			ids.push(id)
		}
		layer.confirm('确定要删除吗？删除后无法恢复！',{icon: 7, title:'操作确认'}, function(index){
			//do something
			layer.close(index);
			var index = layer.load();
			$.post("{:url('del')}",{ids:ids},function(data){
				layer.close(index);
				dialog(data.msg,data.status);
				tableIns.reload()
			})
		});
	}
      //生成桌台
      function createTable(){
          
          var html = '<div style="margin:20px auto;">';
          html+='<div class="layui-form form-label-w8" lay-filter="">';
          html+='	<div class="layui-form-item">';
          html+='		<label class="layui-form-label">桌台数量：</label>';
          html+='		<div class="layui-input-inline" style="width:300px">';
          html+='			<input type="number" name="makecount" value="5" class="layui-input">';
          html+='		</div>';
          html+='	</div>';
          html+='	<div class="layui-form-item">';
          html+='		<label class="layui-form-label">所属分类：</label>';
          html+='		<div class="layui-input-inline" style="width:300px">';
          html+='			<select name="cid"  lay-verify="required">';
          html+='			    <option value="">--选择分类--</option>';
          {foreach $tableCategory as $cate}
          html+='			    <option value="{$cate[\'id\']}">{$cate.name}</option>';
          {/foreach}
          html+='			</select>';
          html+='		</div>';
          html+='	</div>';
          html+='	<div class="layui-form-item">';
          html+='		<label class="layui-form-label">名称前缀：</label>';
          html+='		<div class="layui-input-inline" style="width:300px">';
          html+='			<input type="text" name="prefix" value="" placeholder="请输入餐桌名称的前缀，例如“A”" class="layui-input">';
          html+='		</div><div class="layui-form-mid layui-word-aux" style="margin-left:10px;">例如：“A”</div>';
          html+='	</div>';
          html+='	<div class="layui-form-item">';
          html+='		<label class="layui-form-label">起始序号：</label>';
          html+='		<div class="layui-input-inline" style="width:300px">';
          html+='			<input type="text" name="start" value="1" placeholder="请输入起始序号" class="layui-input">';
          html+='		</div><div class="layui-form-mid layui-word-aux" style="margin-left:10px;">纯数字，默认1，生成的序号小于10自动补0</div>';
          html+='	</div>';
          html+='	<div class="layui-form-item">';
          html+='		<label class="layui-form-label">不包含的数字：</label>';
          html+='		<div class="layui-input-inline" style="width:300px">';
          html+='			<input type="text" name="not_have_number" value="" placeholder="不包含的数字,英文逗号“,”隔开" class="layui-input">';
          html+='		</div><div class="layui-form-mid layui-word-aux" style="margin-left:10px;">例如：“1,2”</div>';
          html+='	</div>';
          html+='	<div class="layui-form-item">';
          html+='		<label class="layui-form-label">座位数：</label>';
          html+='		<div class="layui-input-inline" style="width:300px">';
          html+='			<input type="number" min="1" max="200" name="seat" value="" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">';
          html+='	    </div>';
          html+='	</div>';
          html+='	<div class="layui-form-item">';
          html+='		<label class="layui-form-label">预定：</label>';
          html+='		<div class="layui-input-inline" style="width:300px">';
          html+='		<input type="radio" name="canbook" value="0" checked="true" title="关闭" >';
          html+='       <input type="radio" name="canbook" value="1" title="开启" >';
          html+='	    </div>';
          html+='	</div>';
          {if getcustom('restaurant_table_after_pay_clean')}
          html+='	<div class="layui-form-item">';
          html+='		<label class="layui-form-label">自动清台：</label>';
          html+='		<div class="layui-input-inline" style="width:300px">';
          html+='		<input type="radio" name="auto_clean" value="0" checked="true" title="关闭" >';
          html+='       <input type="radio" name="auto_clean" value="1" title="开启" >';
          html+='	    </div>';
          html+='	</div>';
          {/if}
          {if getcustom('restaurant_shop_pindan')}
          html+='	<div class="layui-form-item">';
          html+='		<label class="layui-form-label">餐后付款模式：</label>';
          html+='		<div class="layui-input-inline" style="width:300px">';
          html+='		<input type="radio" name="pindan_status" value="0" checked="true" title="关闭" >';
          html+='       <input type="radio" name="pindan_status" value="1" title="开启" >';
          html+='	    </div>';
          html+='	</div>';
          {/if}
          {if getcustom('restaurant_table_timing')}
          html +='  <div class="layui-form-item">';
          html+='	    <label class="layui-form-label">计时收费：</label>';
          html+='		<div class="layui-input-inline" style="width: 400px">';
          html+='		<input type="radio" name="timing_fee_type" checked="true" title="不计时收费" value="0" lay-filter="timing_fee_type"/>';
          html+='		<input type="radio" name="timing_fee_type" title="阶梯计费" value="1"  lay-filter="timing_fee_type"/>';
          html+='		<input type="radio" name="timing_fee_type" title="时段计费" value="2" lay-filter="timing_fee_type"/>';
          html+='	</div>';

          html+='    <div class="layui-form-item" id="jieti_set" style="display:none">';
          html+='      <label class="layui-form-label">阶梯计费：</label>';
          html+='      <div class="layui-input-inline" style="width:600px">';
          html+='        <table   class="layui-table" style="width:600px">';
          html+='             <thead><tr><th>阶梯价格设置</th><th>操作</th></tr> </thead>';
          html+='             <tbody id="jieti_discountdiv" class="timeset" ></tbody>';
          html+='             <tr><td colspan="2" style="text-align:center;"><button type="button" class="layui-btn  " onclick="addjl()">添加</button></td></tr>';
          html+='        </table>';
          html+='      </div>';
          html+='    </div>';

          html+='    <div class="layui-form-item" id="time_set" style="display:none">';
          html+='      <label class="layui-form-label">时段计费：</label>';
          html+='      <div class="layui-input-inline" style="width:600px">';
          html+='        <table   class="layui-table" style="width:600px">';
          html+='             <thead> <tr><th>时间段价格设置</th><th>操作</th></tr></thead>';
          html+='             <tbody class="timeset" id="time_discountdiv" > </tbody>';
          html+='             <tr><td colspan="2" style="text-align:center;"><button type="button" class="layui-btn  " onclick="addtime()">添加</button></td></tr>';
          html+='        </table>';
          html+='      </div>';
          html+='    </div>';
          {/if}
          {if getcustom('restaurant_table_minprice')}   
          html+='	<div class="layui-form-item">';
          html+='		<label class="layui-form-label">最低消费：</label>';
          html+='		<div class="layui-input-inline" style="width:300px">';
          html+='			<input type="number" min="0"  name="minprice" value="" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">';
          html+='	    </div>';
          html+='	</div>';
          {/if}
          html+='	<div class="layui-form-item">';
          html+='		<label class="layui-form-label">绑定打印机：</label>';
          html+='		<div class="layui-input-inline" style="width:300px">';
           
          {foreach $printArr as $k=>$v}
          html+='			<input type="checkbox" name="print_ids[]" value="{$k}" title="{$v}" lay-skin="primary">';
           {/foreach}
           html+='	    </div>';
           html+='      <div class="layui-form-mid layui-word-aux" style="margin-left:160px;">普通场景在菜品中绑定打印区域即可，此处绑定打印机适合包间对应多个吧台出单的场景</div>';      
          html+='	</div>';
          
          html+='	<div class="layui-form-item" style="margin-top:30px">';
          html+='		<label class="layui-form-label"></label>';
          html+='		<div class="layui-input-inline">';
          html+='			<button class="layui-btn layui-btn-normal" lay-submit lay-filter="submit_create">确 定</button>';
          html+='		</div>';
          html+='	</div>';
          html+='</div>';
          html+='</div>'
               
          var makelayer = layer.open({type:1,area: ['800px', '600px'],title:'批量创建桌台',content:html,shadeClose:true,closeBtn:1})
          layui.form.render();
          layui.form.on('submit(submit_create)', function(obj){
              var field = obj.field;
              if(field.cid ==''){
                  return layer.msg('请选择分类');
              }
              var index= layer.load();
              $.post("{:url('createTables')}",field,function(data){
                  layer.close(index);
                  layer.close(makelayer)
                  dialog(data.msg,data.status);
                  tableIns.reload()
              })
          })
           
      }
	</script>

  <script>
      {if getcustom('restaurant_table_timing')}
      layui.form.on('radio(timing_fee_type)',function(data){
          if(data.value=="0"){
              $('#jieti_set').hide();
              $('#time_set').hide();
          }
          if(data.value=="1"){
              $('#jieti_set').show();
              $('#time_set').hide();
          }
          if(data.value=="2"){
              $('#jieti_set').hide();
              $('#time_set').show();
          }
      });
      function addjl(){
          var num	= $('#jieti_discountdiv').find('tr').length;
          if(num >= 4){
              layer.alert('最多添加4个');
              return;
          }
          var gghtml = '<tr>';
          gghtml +='<td ><div><input type="number" class="layui-input" name="jt[start][]" value="" placeholder="起" style="width:90px" min="1"> ~ ' +
              '<input type="number" class="layui-input" name="jt[end][]" value="" style="width:90px" placeholder="止" min="1"/>' +
              '	<input type="number" class="layui-input" name="jt[money][]" value="" style="width:90px" placeholder="单价"/> 元<input type="number" class="layui-input" name="jt[minute][]" value="" style="width:90px" min="1" placeholder="分钟数"/>分钟' +
              '</div></td>';
          gghtml += '<td><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="$(this).parent().parent().remove()">删除</button></td>';
          gghtml += '</tr>';

          $('#jieti_discountdiv').append(gghtml);
      }
      function addtime(){
          var num	= $('#time_discountdiv').find('tr').length;
          if(num >= 10){
              layer.alert('最多添加10个');
              return;
          }
          var gghtml = '<tr>';
          gghtml +='<td ><div><input type="text" class="layui-input timedata" name="time[start][]" value="" placeholder="起" style="width:90px" > ~' ;
          gghtml +='	<input type="text" class="layui-input timedata" name="time[end][]" value="" style="width:90px" placeholder="止" />' ;
          gghtml +='	<input type="number" class="layui-input " name="time[money][]" value="" style="width:90px" placeholder="单价"/> 元<input type="number" class="layui-input" name="time[minute][]" value="" style="width:90px" min="1" placeholder="分钟数"/>分钟' ;
          gghtml +='</div></td>';
          gghtml += '<td><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="$(this).parent().parent().remove()">删除</button></td>';
          gghtml += '</tr>';
          $('#time_discountdiv').append(gghtml);
          $('.timedata').each(function() {
              layui.laydate.render({elem:this,type: 'time',trigger: 'click',format:'HH:mm' });
          });
      }
      {/if}
  </script>
	{include file="public/copyright"/}

</body>
</html>